package com.example.saiweisi.controller.systemAdminController;

import com.example.saiweisi.common.Result;
import com.example.saiweisi.controller.request.WaiterAdminRequest;
import com.example.saiweisi.model.WaiterAdmin;
import com.example.saiweisi.service.interf.IWaiterAdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/waiteradmin")
@RestController
@CrossOrigin
@Slf4j
public class WaiterAdminController {
    @Autowired
    private IWaiterAdminService waiterAdminService;
    //分页查询
    @GetMapping("/page")
    public Result page(WaiterAdminRequest waiterAdminRequest) {
        return Result.success(waiterAdminService.page(waiterAdminRequest));
    }
    //添加
    @PostMapping("/add")
    public Result addwaiteradmin(@RequestBody WaiterAdmin waiterAdmin){
        waiterAdminService.addwaiteradmin(waiterAdmin);
        return Result.success();
    }
    //删除
    @DeleteMapping("/delete{waiterAdminId}")
    public Result deletewaiteradmin(@PathVariable Integer waiterAdminId){
        System.out.println(waiterAdminId);
        waiterAdminService.deletewaiteradmin(waiterAdminId);
        return Result.success();
    }
    //重置密码
    @PutMapping("/resetpassword{waiterAdminId}")
    public Result resetpassword(@PathVariable Integer waiterAdminId){
        waiterAdminService.resetPassword(waiterAdminId);
        return Result.success();
    }
    //批量删除
    @PostMapping("/deletes")
    public Result deleteswaiteradmin(@RequestBody List<Integer> waiterAdminIds){
        waiterAdminService.deleteswaiteradmin(waiterAdminIds);
        return Result.success();
    }
    //根据id查找
    @GetMapping("/{waiterAdminId}")
    public Result getById(@PathVariable Integer waiterAdminId){
        WaiterAdmin waiterAdmin =waiterAdminService.getById(waiterAdminId);
        return Result.success(waiterAdmin);
    }
    //修改
    @PutMapping("/update")
    public Result updatewaiteradmin(@RequestBody WaiterAdmin waiterAdmin){
        waiterAdminService.updatewaiteradmin(waiterAdmin);
        return Result.success();
    }
}
